from typing import List

class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        ans = []
        def dfs(nums, path):
            if len(path) == len(nums):
                ans.append(path[:])
                return
            for i in range(len(nums)):
                cur = nums[i]
                if cur in path:
                    continue
                path.append(cur)
                dfs(nums, path)
                path.pop()
        dfs(nums, [])
        return ans